<template>
  <view class="header flex flex-x-between flex-y-center fz30 bg-white">
    <view class="flex1 flex flex-y-center">
      <sw-icons color="#008afe" icon="icon-didian" class="mr10"></sw-icons>
      <view class="text-e1">{{ state.networkName }}</view>
    </view>
    <view>营业时间： {{ state.serviceTime ? state.serviceTime.split(':')[0] : '-' }}小时</view>
  </view>
</template>

<script setup>
import { reactive, getCurrentInstance } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { queryByMainBoardId } from '@/common/js/getData.js';

const { proxy } = getCurrentInstance();

const state = reactive({
  networkName: '',
  serviceTime: ''
});

// 获取网点信息
const getInfo = () => {
  const data = {
    mainboardId: getApp().globalData.mainboardId
  };
  queryByMainBoardId(data, { hideLoad: true }).then(res => {
    const { result } = res;
    getApp().globalData.networkName = result.networkName;
    getApp().globalData.serviceTime = result.serviceTime;
    state.networkName = getApp().globalData.networkName;
    state.serviceTime = getApp().globalData.serviceTime;
  });
};

// 页面加载完成
onLoad(async () => {
  await proxy.$onLaunched;
  state.networkName = getApp().globalData.networkName;
  state.serviceTime = getApp().globalData.serviceTime;
  if (!(state.networkName && state.serviceTime)) {
    getInfo();
  }
});
</script>

<style lang="less" scoped></style>
